Code coverage report for src/aside/aside.js

Statements: 96.97% (32 / 33)      Branches: 88.89% (16 / 18)      Functions: 100% (11 / 11)      Lines: 96.77% (30 / 31)      Ignored: none     

All files » src/aside/ » aside.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97    1       22                             22   1   22     22   22   22       22               21   21         21 21 168       21 21 84 4       21 42 16         21 15 15             21     21     21 21 21 21              
'use strict';
 
angular.module('mgcrea.ngStrap.aside', ['mgcrea.ngStrap.modal'])
 
  .provider('$aside', function() {
 
    var defaults = this.defaults = {
      animation: 'am-fade-and-slide-right',
      prefixClass: 'aside',
      prefixEvent: 'aside',
      placement: 'right',
      template: 'aside/aside.tpl.html',
      contentTemplate: false,
      container: false,
      element: null,
      backdrop: true,
      keyboard: true,
      html: false,
      show: true
    };
 
    this.$get = function($modal) {
 
      function AsideFactory(config) {
 
        var $aside = {};
 
        // Common vars
        var options = angular.extend({}, defaults, config);
 
        $aside = $modal(options);
 
        return $aside;
 
      }
 
      return AsideFactory;
 
    };
 
  })
 
  .directive('bsAside', function($window, $sce, $aside) {
 
    var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout;
 
    return {
      restrict: 'EAC',
      scope: true,
      link: function postLink(scope, element, attr, transclusion) {
        // Directive options
        var options = {scope: scope, element: element, show: false};
        angular.forEach(['template', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation'], function(key) {
          if(angular.isDefined(attr[key])) options[key] = attr[key];
        });
 
        // use string regex match boolean attr falsy values, leave truthy values be
        var falseValueRegExp = /^(false|0|)$/i;
        angular.forEach(['backdrop', 'keyboard', 'html', 'container'], function(key) {
          if(angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key]))
            options[key] = false;
        });
 
        // Support scope as data-attrs
        angular.forEach(['title', 'content'], function(key) {
          attr[key] && attr.$observe(key, function(newValue, oldValue) {
            scope[key] = $sce.trustAsHtml(newValue);
          });
        });
 
        // Support scope as an object
        attr.bsAside && scope.$watch(attr.bsAside, function(newValue, oldValue) {
          Eif(angular.isObject(newValue)) {
            angular.extend(scope, newValue);
          } else {
            scope.content = newValue;
          }
        }, true);
 
        // Initialize aside
        var aside = $aside(options);
 
        // Trigger
        element.on(attr.trigger || 'click', aside.toggle);
 
        // Garbage collection
        scope.$on('$destroy', function() {
          Eif (aside) aside.destroy();
          options = null;
          aside = null;
        });
 
      }
    };
 
  });